<template>
	<view class="select-role-top">
		<view class="selece-role-content">
			<view class="selece-role-icon">
				<view class="select-role-img">
					<uv-avatar :src="url + userInfo.userAvatar"></uv-avatar>
				</view>
				<view class="select-role-name">{{ userInfo.userName }}</view>
			</view>
			<scroll-view scroll-y style="max-height: 570rpx;">
				<view v-for="item in roleList" :key="item.EmployeeId">
					<view class='select switch_btn' @click="switchRole(item.EmployeeId)">
						<view>
							<view style="display: flex;align-items: center;">
								<view class="select-role" v-if="item.CompanyType == 0">平台</view>
								<view class="select-role-custom" v-if="item.CompanyType == 1">客户</view>
								<view class='select-name'>
									{{ item.EmployeeName }}
								</view>
								<!-- <text ></text> -->
							</view>
							<view class="select-role-jurisdiction">
								{{ item.RoleList }}
							</view>
						</view>
						<view style="display: flex;align-items: center;">
							<text class="personal-login" v-if="item.isCurrent">当前登录</text>
							<uv-icon name="arrow-right" color="#848484"></uv-icon>
							<!-- <image src="../image/right.svg" style="width:33rpx;height:33rpx;margin-left: 4rpx;"></image> -->
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import store from '@/store'
import { serverPort } from '@/utils/request'
import customRouter from '@/utils/customRouter.js'
import request from '@/utils/request'
export default {
	data() {
		return {
			url: '',
			roleList: []
		};
	},
	computed: {
		userInfo() {
			return store.state.userInfo
		}
	},
	created() {
		this.url = serverPort
		this.getRoleList()
	},
	methods: {
		getRoleList() {
			request.get("/api/CurrentUser/GetUserBindEmployeeList").then(res => {
				if (res.length < 1) return
				console.log(this.userInfo);
				res.forEach(t => {
					t.isCurrent = this.userInfo.Id == t.EmployeeId
				})
				this.roleList = res
				console.log(this.roleList);
			})
		},
		switchRole(employeeId) {
			request.post("/api/AuthUser/WeChatChooseEmployee", { employeeId }).then(res => {
				uni.showToast({
					title: res.Message,
					icon: 'none'
				})
				store.commit('userInfo/editUserInfo', { token: res.Data })
				store.dispatch('userInfo/getUserInfo')
				customRouter.reLaunch({
					url: '/pages/tabbar/user/user'
				})
			})
		}
	}
}
</script>

<style lang="scss">
@import './selectRole.scss'
</style>
